package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class User extends AnyPage {

	public User(PageManager pages) {
		super(pages);
	}

	// Аннотация FindBy реализация работы с элементами, к-е присутствуют на
	// странице
	@FindBy (id="logo") 
	private WebElement Logo;
	@FindBy (id="task") 
	private WebElement Task;
		@FindBy (id="L_MENU_UNIONTASKS-menupoint") 
		private WebElement Tasks;
		@FindBy (id="L_INFORMER_CREATETASK-menupoint") 
		private WebElement Createtask;
		@FindBy (id="L_MENU_TASKSANDEMP-menupoint") 
		private WebElement Tasksandemployers;
		@FindBy (id="L_MENU_TARCHIVE-menupoint") 
		private WebElement  Tasksarchive;
		@FindBy (id="L_MENU_ONCONTROL-menupoin") 
		private WebElement Oncontrol;
		@FindBy (id="L_MENU_SUB_PROJECTS-menupoint") 
		private WebElement Projects;
	@FindBy (id="doc") 
	private WebElement Doc;
		@FindBy (id="L_MENU_MYDOCS_FORASSIGNMENT-menupoint") 
		private WebElement DocsForAss;
		@FindBy (id="L_MENU_MYDOCS_FOREXECUTION-menupoint") 
		private WebElement DocsForExe;
		@FindBy (id="L_MENU_MY_REVIEWED_DOCUMENTS-menupoint") 
		private WebElement MyRevDocs;
		@FindBy (id="L_MENU_MYDOCS_FORINFORMATION-menupoint") 
		private WebElement DocsForInfo;
		@FindBy (id="L_MENU_DOCS_ONASSIGNMENT-menupoint") 
		private WebElement DocsOnAss;
		@FindBy (id="L_MENU_DOCS_ONEXECUTION-menupoint") 
		private WebElement DocsOnExe;
		@FindBy (id="L_DOCUMENT_NEW-menupoint") 
		private WebElement Createdoc;
		@FindBy (id="L_MENU_DOCS_FROMME-menupoint") 
		private WebElement DoscFromMe;
		@FindBy (id="L_MENU_DOCS_REGISTRY-menupoint") 
		private WebElement DocsRegistry;
		@FindBy (id="L_MENU_DOCS_DETAL_REGISTRY_COUNTERS-menupoint") 
		private WebElement DocsRegistryExt;
		@FindBy (id="L_MENU_DOCS_REPORT-menupoint") 
		private WebElement DocsRrport;
		@FindBy (id="L_MENU_DOCUMENT_STATISTIC-menupoint") 
		private WebElement DocsStat;
		@FindBy (id="L_MENU_DOCS_ARCHIVE-menupoint") 
		private WebElement DocsArchive;
	@FindBy (id="mes") 
	private WebElement Mes;
		@FindBy (id="L_MENU_UIONSENDEDIT-menupoint") 
		private WebElement Messages;
		@FindBy (id="L_MENU_NEW_MESSAGE_ADD-menupoint") 
		private WebElement AddMessage;
		@FindBy (id="L_MENU_MESSAGE_ADD-menupoint") 
		private WebElement AddAnnouncement;
	@FindBy (id="col") 
	private WebElement Cal;
	@FindBy (id="lib") 
	private WebElement Lib;
	@FindBy (id="instr") 
	private WebElement Instr;
		@FindBy (id="L_ADDRESS_BOOK-menupoint")
		private WebElement Addressbook;
		@FindBy (id="L_MENU_REPORTS-menupoint")
		private WebElement Reports;
			//L_MENU_ACTIONTAPE-menupoint
			//L_MENU_ACTONMYTASKS-menupoint
			//L_MENU_TASK_SUPERREPORT-menupoint
			//L_GLOBAL_USERS_REPORT-menupoint
			//L_MENU_CUREMPTASKS-menupoint
			//L_MENU_TASKSPERDIV-menupoint
			//L_MENU_OUTDATEDTASKS-menupoint
			//L_MENU_TASKS_ON_PERIOD-menupoint
			//L_REPORT_EXEC_BUT_OUTDATES-menupoint
			//L_MENU_USERPROPS-menupoint
			//L_AU_PERMISSIONS_OF_EMPLOYER-menupoint
			//L_GLOBAL_USER_REPORTS-menupoint	
		@FindBy (id="L_MENU_ADMINISTRATION-menupoint")
		private WebElement Administration;
			@FindBy (id="L_MENU_SYSTEMOPTIONS-menupoint")
			private WebElement Systemoptions;
			@FindBy (id="L_MENU_USERADMIN-menupoint")
			private WebElement Useradmin;
			@FindBy (id="L_GLOBAL_USER_PROFILES-menupoint")
			private WebElement Userprofiles;
			@FindBy (id="L_MENU_GROUPRIGHTS-menupoint")
			private WebElement Grouprights;
			@FindBy (id="L_MENU_USERRIGHTS-menupoint")
			private WebElement Userrights;
			@FindBy (id="L_MENU_PERM-menupoint")
			private WebElement Perm;
			@FindBy (id="L_MENU_ADMIN_MENUSETTINGS-menupoint")
			private WebElement Menusettings;
			@FindBy (id="L_MENU_ADMIN_TYPE_TASK-menupoint")
			private WebElement Tasktypelist;
			@FindBy (id="L_GLOBAL_TASK_COUNT-menupoint")
			private WebElement Taskcounters;
			@FindBy (id="L_GLOBAL_MODEL_MESSAGE-menupoint")
			private WebElement Notifytempl;
			@FindBy (id="L_MENU_ADMIN_NOTIFICATION_SETTINGS-menupoint")
			private WebElement Notifysettings;
			@FindBy (id="L_MENU_MAIL_SMS_TEST-menupoint")
			private WebElement Notifytest;
			@FindBy (id="L_MENU_ADRESSBOOK_SETTINGS-menupoint")
			private WebElement Addressbooksettings;
			@FindBy (id="L_GLOBAL_WORK_CALENDAR-menupoint")
			private WebElement Workcalendar;
			@FindBy (id="L_MENU_TABLES-menupoint")
			private WebElement Tables;
			@FindBy (id="L_MENU_ADMIN_DICTIONARY-menupoint")
			private WebElement Dictionary;
			@FindBy (id="L_GLOBAL_PLUGINS-menupoint")
			private WebElement Plugins;
			@FindBy (id="L_SEARCH_ADMIN-menupoint")
			private WebElement Searchsystem;
			@FindBy (id="L_MENU_LDAP-menupoint")
			private WebElement Ldap;
			@FindBy (id="L_MENU_SISTEM_INFORMATION-menupoint")
			private WebElement Tester;
		@FindBy (id="L_DOCPROCESSING-menupoint")
		private WebElement DocAdministration;
			@FindBy (id="L_AU_DOC_CARDS-menupoint")
			private WebElement Doctypes;
			@FindBy (id="L_MENU_ROUTESCHEME_EDITOR-menupoint")
			private WebElement Schemes;
			@FindBy (id="L_AU_DOCUMENT_COUNTERS-menupoint")
			private WebElement Doccounters;
			@FindBy (id="L_GLOBAL_DICTIONARY_EDITOR-menupoint")
			private WebElement Diction;
		@FindBy (id="L_MENU_SECURITY_SYSTEM-menupoint")
		private WebElement Securitysystem;
			//L_GLOBAL_USE_STATISTIC-menupoint
			//L_MENU_TRUST_POLICY-menupoint
			//L_MENU_SECURITYREP5-menupoint
			//L_MENU_SECURITYREP4-menupoint	
			//L_MENU_SECURITYREP3-menupoint
			//L_MENU_SECURITYREP2-menupoint
			//L_MENU_SECURITYREP1-menupoint
			//L_AU_LOG_TASKACCESSFORBIDDEN-menupoint
			//L_MENU_SECURITYREP6-menupoint
			//L_MENU_DELETEDOCUMENTREPORT-menupoint
			//L_MENU_REPORT_OUTERS_IN_LICENSE-menupoint
		@FindBy (id="L_AU_MENU_SETTINGS-menupoint")
		private WebElement Settings;
			@FindBy (id="L_MENU_MYOPTIONS-menupoint")
			private WebElement Myprop;
			@FindBy (id="L_GLOBAL_MOTIWOPTIONS-menupoint")
			private WebElement Personal;
			@FindBy (id="L_MENU_MAILBOX_OPTIONS-menupoint")
			private WebElement Email;
			@FindBy (id="L_MENU_MENUSETTINGS-menupoint")
			private WebElement Menu;
			@FindBy (id="L_MENU_SHADOWS-menupoint")
			private WebElement Ass;
			@FindBy (id="L_MENU_NOTIFICATION_SETTINGS-menupoint")
			private WebElement Notify;
			@FindBy (id="L_GLOBAL_COLOR_SETTINGS-menupoint")
			private WebElement Color;
			@FindBy (id="L_MENU_MYTEMPLATES-menupoint")
			private WebElement Actiontemp;
			@FindBy (id="L_GLOBAL_PERMISSIONS_GROUP-menupoint")
			private WebElement Usersgroups;
			@FindBy (id="L_GLOBAL_EMAIL_EMPLOYER_GROUPS-menupoint")
			private WebElement Outerusersgroups;
			@FindBy (id="L_MENU_OUTER_USERS_EDIT-menupoint")
			private WebElement Outerusers;
			@FindBy (id="L_MENU_TASK_TEMPLATES-menupoint")
			private WebElement Tasktempl;
			@FindBy (id="IWG_TEMPLATE-menupoint")
			private WebElement IWGtempl;
			@FindBy (id="L_CHECKPOINTS_TEMPLATES-menupoint")
			private WebElement Checkpointtempl;
			@FindBy (id="L_MENU_DOCUMENTTEMPLATES-menupoint")
			private WebElement Doctempl;
		@FindBy (id="L_MENU_SOME_PROGRAMMS-menupoint")
		private WebElement Apps;	
	@FindBy (id="help") 
	private WebElement Help;
	@FindBy (id="btn_logout") 
	private WebElement Logout;
	@FindBy (id="btn_close") 
	private WebElement Close;
	@FindBy (xpath="//*[@id='doc-search']/a") 
	private WebElement Docsearch;
	@FindBy (xpath="//*[@id='search-links']/a[2]") 
	private WebElement Tasksearch;
	@FindBy (xpath="//*[@id='search-links']/a[1]") 
	private WebElement Extsearch;
	
	
	Actions action = new Actions(driver);
	
	private void menuclicker(WebElement a,WebElement b) { //Метод простой навигации по меню 
		a.click();
		b.click();
		}
	
	private void submenuclicker(WebElement a,WebElement b,WebElement c) { //Метод сложной навигации по меню
		a.click();
		action.moveToElement(b).perform();
		wait.until(ExpectedConditions.elementToBeClickable(c));
		action.moveToElement(c).perform();
		c.click();
		}
	
// Действия с данными элементами на странице
	
// Переход во внешние ресурсы
	public ExternalResources GoToExternalResources() {
		Logo.click();
		return pages.ExternalResources;
	}
	
//Переход в Задачи/Задачи
	public Uniontasks GoToUniontasks() {
	menuclicker(Task,Tasks);
	return pages.Uniontasks;
	}
//Переход в Задачи/Создать задачу
	public Unionmessagenew GoToUnionmessagenew() {
		menuclicker(Task,Createtask);
		return pages.Unionmessagenew;
	}
//Переход в Задачи/Сотрудники и задачи
	public Tasks GoToTasks() {
		menuclicker(Task,Tasksandemployers);
		return pages.Tasks;
	}
//Переход в Задачи/Архив задач
	public Archivetasksgrid GoToArchivetasksgrid() {
		menuclicker(Task,Tasksarchive);
		return pages.Archivetasksgrid;
	}
//Переход в Задачи/На контроле
	public Formycontrol GoToFormycontrol() {
		menuclicker(Task,Oncontrol);
		return pages.Formycontrol;
	}
//Переход в Задачи/Проекты
	public Gantt GoToGantt() {
		menuclicker(Task,Projects);
		return pages.Gantt;
	}
// Переход в меню - Настройки/Мои реквизиты
	public Pwd GoToPwd() {
		submenuclicker(Instr,Settings,Myprop);
		return pages.Pwd;
	}
	// Переход в меню - Администрирование/Типы таблиц
	public TypesObjectPage GoToTables() {
		submenuclicker(Instr,Administration,Tables);
		return pages.typesObjectPage;
	}
	// Переход в меню - Администрирование/Типы задач
	public TypesObjectPage GoToTasktypelist() {
		submenuclicker(Instr,Administration,Tasktypelist);
		return pages.typesObjectPage;
	}
	// Переход в меню - Администрирование/Справочники
	public TypesObjectPage GoToDictionary() {
		submenuclicker(Instr,Administration,Dictionary);
		return pages.typesObjectPage;
	}
	// Переход в меню - Администрирование/Пользователи
	public UsersAndDepartmentPage GoToUseradmin() {
		submenuclicker(Instr,Administration,Useradmin);	
		return pages.usersAndDepartmentPage;
		}
	// Выход - logout, из системы
		public LoginPage Logout() {
			Logout.click();
			return pages.loginPage;
		}
	// Ожидания появления объектов ОМ
	public User ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(presenceOfElementLocated(By.id("mes")));
		wait.until(presenceOfElementLocated(By.id("col")));
		wait.until(presenceOfElementLocated(By.id("lib")));
		return this;
	}
}
